﻿@model IEnumerable<ESupervision.Models.Document>
@using Microsoft.AspNet.Identity;
@{
    ViewBag.Title = "Student Documents";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>StudentDocument</h2>
<style>
    .hide {
        display: none;
    }
</style>
<div class="panel panel-success">
    <div class="table-responsive">
        <table class="table table-hover  ">
            <tr class="info">
                <th>
                    @Html.DisplayNameFor(model => model.AttachmentFile.FileName)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CreatedTime)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CreatedByUser.FullName)
                </th>

                <th>
                    @Html.DisplayNameFor(model => model.Subject)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Body)
                </th>
                <th></th>
            </tr>
            @foreach (var item in Model)
            {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.AttachmentFile.FileName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CreatedTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CreatedByUser.UserName)
                </td>

                <td>
                    @{ var TempSub = "";
                         if (item.Subject.Length > 20)
                         {
                             TempSub = item.Subject.Substring(0, 20) + " ...";
                         }
                         else
                         {
                             TempSub = item.Subject;
                         }
                    }
                    @TempSub
                    @*@Html.DisplayFor(modelItem => item.Subject)*@
                </td>
                <td>
                    @{ var TempBoby = "";
                         if (item.Body.Length > 20)
                         {
                             TempBoby = item.Body.Substring(0, 20) + "...";
                         }
                         else
                         {

                             TempBoby = item.Body;
                         }
                    }
                    @TempBoby
                    @*@Html.DisplayFor(modelItem => item.Body)*@
                </td>
                <td>
                    @*@Html.ActionLink("Edit", "Edit", "Document", null, new { @class = "btn btn-info btn-sm  glyphicon glyphicon-pencil " })*@
                    @Html.ActionLink("Details", "Details", "Document", new { id = item.DocumentID }, new { @class = "btn btn-success btn-sm  glyphicon glyphicon-pencil " })
                    @{
                if (User.Identity.GetUserId() == item.CreatedByUserId)
                {
                        @Html.ActionLink("Delete", "Delete", "Document", new { id = item.DocumentID }, new { @class = "btn btn-warning btn-sm  glyphicon glyphicon-pencil " })

                }
                else
                {
                        @Html.ActionLink("Delete", "Delete", "Document", new { id = item.DocumentID }, new { @class = "btn btn-warning btn-sm  glyphicon glyphicon-pencil hide", @disabled = "disabled" })

                }
                    }
                </td>
            </tr>
            }

        </table>
    </div>
</div>
